
package com.vids.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vids.mapper.NonMotorVehicleMapper;
import com.vids.model.entity.NonMotorVehicle;
import com.vids.model.param.*;
import com.vids.model.vo.SubImageInfoVo;
import com.vids.service.IImageBusinessService;
import com.vids.service.INonMotorVehicleService;
import com.vids.utils.BeanUtilss;
import com.vids.utils.QueryUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 机动车 服务实现类
 * </p>
 *
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class NonMotorVehicleServiceImpl extends ServiceImpl<NonMotorVehicleMapper, NonMotorVehicle>
	implements INonMotorVehicleService {

    public final static String type = "01";

    private final NonMotorVehicleMapper nonMotorVehicleMapper;

    private final IImageBusinessService tBigDataImageBusinessServiceImpl;

    @Override
    public NonMotorVehicle findByNonMotorVehicleID(String NonMotorVehicleID) {
	return baseMapper.selectById(NonMotorVehicleID);
    }

    @Override
    public void deleteByNonMotorVehicleID(String NonMotorVehicleID) {
	baseMapper.deleteById(NonMotorVehicleID);
    }

    /*
     * List<SubImageInfoVo> volist = tBigDataImageBusinessServiceImpl
     * .findSubImageInfoVo(row.getMotorVehicleID(), type);
     */

    @Override
    public NonMotorVehicleBatchParam getNonMotorVehicleList(Map<String, Object> map) {
	// 无条件查询默认返回所有
	if (map == null || map.size() == 0) {
	    List<NonMotorVehicle> resultList = nonMotorVehicleMapper.selectList(null);
	    return buildResultModel(resultList);
	}
	Map<String, Object> paramMap = QueryUtils.buildParam(map);
	List<NonMotorVehicle> resultList = nonMotorVehicleMapper.selectByMap(paramMap);
	return buildResultModel(resultList);
    }

    private NonMotorVehicleBatchParam buildResultModel(List<NonMotorVehicle> resultList) {
	if (resultList != null && resultList.size() > 0) {
	    NonMotorVehicleBatchParam param = new NonMotorVehicleBatchParam();
	    NonMotorVehicleBatchModel batchModel = new NonMotorVehicleBatchModel();
	    List<NonMotorVehicleModel> modelList = new ArrayList<>();
	    for (NonMotorVehicle car : resultList) {
			NonMotorVehicleModel model = BeanUtilss.transferObjectCommon(car, NonMotorVehicleModel.class);
		List<SubImageInfoVo> volist = tBigDataImageBusinessServiceImpl
			.findSubImageInfoVo(car.getNonMotorVehicleID(), type);
		SubImageBatchParam imageBatchParam = new SubImageBatchParam();
		imageBatchParam.setSubImageInfoObject(volist);
		model.setSubImageList(imageBatchParam);
		modelList.add(model);
	    }
	    batchModel.setNonMotorVehicleObject(modelList);
	    param.setNonMotorVehicleListObject(batchModel);
	    return param;
	}
	return null;
    }
}
